package com.quanling.swing.moju;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.file.FileReader;
import cn.hutool.core.text.StrSpliter;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ReUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.ftp.Ftp;
import cn.hutool.json.JSONUtil;
import cn.hutool.setting.dialect.Props;
import com.quanling.swing.moju.listeners.GenerateButtonListener;
import lombok.Data;

import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.prefs.Preferences;

/**
 * @author tangxianjie
 */
@Data
public class MainFrame {

    private JFrame frame;
    private JTextField inputFile;
    private JTextField outputFile;
    private JTextField ftpHost;
    private JTextField ftpUserName;
    private JTextField textField_5;
    private JTextField textField_6;
    private JPasswordField ftpPass;
    private JTextField textField_4;
    private JTextField textField_7;
    private JTextField textField_8;
    private JTextField textField_9;
    private JTextField textField_10;
    private JTextField textField_11;
    private JTextField textField_12;
    private JTextField textField_13;
    private JTextField textField_14;
    private JTextField textField_15;
    private JTextField textField_16;
    private JTextField textField_17;
    private JTextField textField_18;
    private JTextField textField_19;
    private JTextField textField_20;
    private JTextField textField_21;
    private JTextField textField_22;
    private JTextField textField_23;
    private JTextField textField_24;
    private JTextField textField_25;
    private JTextField tab2_input1;
    private JTextField tab2_input2;
    private JTextField tab2_input3;
    private JTextField tab2_input4;
    private JTextField tab2_input5;
    private JTextField tab2_input6;
    private JPasswordField tab2_pass;
    private JTextField textField_32;
    private JTextField textField_33;
    private JTextField textField_34;
    private JTextField textField_35;
    private JTextField textField_36;
    private JTextField textField_37;
    private JTextField textField_38;

    private Ftp ftp = null;
    private Map<String, BigDecimal> inputReadMap = new HashMap<>();
    private static Props props = new Props("init.properties");
    //弹出窗体
    private PopupFrame popupFrame = null;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        final Date endDate = props.getDate("soft.end.time");
        if (new Date().after(endDate)) {
            System.exit(0);
        }
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {
                    MainFrame window = new MainFrame();
                    window.frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the application.
     */
    public MainFrame() {
        initialize();
        initFilePath();
    }

    private void initFilePath() {
        Preferences pref = Preferences.userRoot().node("/com/quanling/inputFilePath");
        String lastPath = pref.get("lastPath", "");
        if (StrUtil.isNotEmpty(lastPath)) {
            inputFile.setText(lastPath);
        }
        pref = Preferences.userRoot().node("/com/quanling/outPutFilePath");
        lastPath = pref.get("lastPath", "");
        if (StrUtil.isNotEmpty(lastPath)) {
            outputFile.setText(lastPath);
        }
    }


    /**
     * Initialize the contents of the frame.
     */
    private void initialize() {
        frame = new JFrame();
        frame.setIconImage(Toolkit.getDefaultToolkit().getImage("src/main/resources/Hilfebilder/Kuekanal.jpg"));
        frame.setResizable(false);
        frame.setTitle("专业五轴工具磨优化软件");
        frame.setBounds(100, 100, 746, 600);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().setLayout(null);

        JLabel lblNewLabel = new JLabel("输入文件：");
        lblNewLabel.setBounds(23, 10, 68, 20);
        frame.getContentPane().add(lblNewLabel);

        inputFile = new JTextField();
        inputFile.setBounds(101, 8, 511, 25);
        frame.getContentPane().add(inputFile);
        inputFile.setColumns(10);

        JButton btnNewButton = new JButton("浏览");
        btnNewButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                Preferences pref = Preferences.userRoot().node("/com/quanling/inputFilePath");
                String lastPath = pref.get("lastPath", "");
                JFileChooser jfc = null;
                if (!lastPath.equals("")) {
                    jfc = new JFileChooser(lastPath);
                } else {

                    jfc = new JFileChooser();
                }
                jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
                FileFilter filter = new FileNameExtensionFilter("模板文件（.mcd）", "mcd");// 设置文件过滤器，只列出JPG或GIF格式的图片
                jfc.setFileFilter(filter);
                jfc.showDialog(new JLabel(), "选择");
                //TODO 记录上次的文件夹位置
//                jfc.setCurrentDirectory();
                File file = jfc.getSelectedFile();
                if (ObjectUtil.isNull(file)) {
                    return;
                }
                if (file.isDirectory()) {
                    System.out.println("文件:" + file.getAbsolutePath());
                } else if (file.isFile()) {
                    System.out.println("文件:" + file.getAbsolutePath());
                    inputFile.setText(file.getAbsolutePath());
                    readTempleFile(file);
                    textField_5.setText(NumberUtil.sub(inputReadMap.get("[NR_DATA(1)]"), inputReadMap.get("[NR_DATA(67)]")) + "");
                    textField_4.setText(inputReadMap.get("[NR_DATA(67)]") + "");
                    textField_7.setText(inputReadMap.get("[NR_DATA(9)]") + "");
                    textField_9.setText(inputReadMap.get("[NR_DATA(7)]") + "");

                    textField_8.setText(inputReadMap.get("[NR_DATA(41)]") + "");
                    //测量A轴位置
                    textField_16.setText(inputReadMap.get("[NR_DATA(2)]") + "");
                    textField_17.setText(inputReadMap.get("[NR_DATA(70)]") + "");
                }
                pref.put("lastPath", file.getAbsolutePath());
            }
        });
        btnNewButton.setBounds(641, 8, 75, 25);
        frame.getContentPane().add(btnNewButton);

        JLabel label = new JLabel("输出文件：");
        label.setBounds(23, 48, 68, 20);
        frame.getContentPane().add(label);

        outputFile = new JTextField();
        outputFile.setColumns(10);
        outputFile.setBounds(101, 46, 511, 25);
        frame.getContentPane().add(outputFile);

        JButton button = new JButton("浏览");
        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Preferences pref = Preferences.userRoot().node("/com/quanling/outPutFilePath");
                String lastPath = pref.get("lastPath", "");
                JFileChooser jfc = null;
                if (!lastPath.equals("")) {
                    jfc = new JFileChooser(lastPath);
                } else {

                    jfc = new JFileChooser();
                }
                jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                jfc.showDialog(new JLabel(), "选择");
                File file = jfc.getSelectedFile();
                if (ObjectUtil.isNull(file)) {
                    return;
                }
                if (file.isFile()) {
                    System.out.println("文件:" + file.getAbsolutePath());
                } else if (file.isDirectory()) {
                    System.out.println("文件夹:" + file.getAbsolutePath());
                    outputFile.setText(file.getAbsolutePath());
                }
                pref.put("lastPath", file.getAbsolutePath());
            }
        });
        button.setBounds(641, 46, 75, 25);
        frame.getContentPane().add(button);

        JLabel lblFtp = new JLabel("FTP服务器：");
        lblFtp.setBounds(26, 89, 80, 15);
        frame.getContentPane().add(lblFtp);

        ftpHost = new JTextField();
        ftpHost.setBounds(101, 86, 130, 21);
        frame.getContentPane().add(ftpHost);
        ftpHost.setColumns(10);

        JLabel label_1 = new JLabel("用户名：");
        label_1.setBounds(246, 89, 54, 15);
        frame.getContentPane().add(label_1);

        ftpUserName = new JTextField();
        ftpUserName.setColumns(10);
        ftpUserName.setBounds(310, 86, 130, 21);
        frame.getContentPane().add(ftpUserName);

        JLabel label_2 = new JLabel("密码：");
        label_2.setBounds(450, 89, 40, 15);
        frame.getContentPane().add(label_2);

        JButton button_1 = new JButton("生成加工程序");
        button_1.setBounds(41, 531, 118, 25);
        button_1.addActionListener(new GenerateButtonListener(this));
        frame.getContentPane().add(button_1);

        JButton button_2 = new JButton("上传");
        button_2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                //如果没有选中输出文件夹
                if (StrUtil.isEmpty(outputFile.getText())) {
                    JOptionPane.showMessageDialog(
                            frame,
                            "请选择输出文件路径",
                            "提示",
                            JOptionPane.INFORMATION_MESSAGE
                    );
                    outputFile.requestFocus();
                    return;
                }

                //如果没有连接ftp
                if (ObjectUtil.isEmpty(ftp)) {
                    JOptionPane.showMessageDialog(
                            frame,
                            "请先建立ftp连接!",
                            "提示",
                            JOptionPane.INFORMATION_MESSAGE
                    );
                    ftpHost.requestFocus();
                    return;
                }

                try {
                    ftp.upload(props.getStr("ftp.remote.path"), FileUtil.file(outputFile.getText() + Constants.OUTPUT_FILE_NAME));
                    JOptionPane.showMessageDialog(
                            frame,
                            "上传成功!",
                            "提示",
                            JOptionPane.INFORMATION_MESSAGE
                    );
                } catch (Exception e) {
                    e.printStackTrace();
                    JOptionPane.showMessageDialog(
                            frame,
                            "上传失败" + e.getMessage(),
                            "提示",
                            JOptionPane.INFORMATION_MESSAGE
                    );
                }

            }
        });
        button_2.setBounds(347, 531, 93, 25);
        frame.getContentPane().add(button_2);

        JButton button_3 = new JButton("退出");
        button_3.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });
        button_3.setBounds(595, 531, 93, 25);
        frame.getContentPane().add(button_3);

        JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
        tabbedPane.setBounds(10, 128, 720, 390);
        frame.getContentPane().add(tabbedPane);

        JPanel panel_1 = new JPanel();
        panel_1.setBackground(Color.WHITE);
        tabbedPane.addTab("探针设定值", null, panel_1, null);
        panel_1.setLayout(null);

        JLabel label_3 = new JLabel("夹紧外露长度");
        label_3.setBounds(10, 10, 89, 15);
        panel_1.add(label_3);

        textField_5 = new JTextField();
        textField_5.setEditable(false);
        textField_5.setText("0.0000");
        textField_5.setBounds(111, 10, 90, 21);
        panel_1.add(textField_5);
        textField_5.setColumns(10);
        textField_5.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                showPopFrame("/Hilfebilder/Fraes/geabspfr.jpg");
            }
        });

        JLabel lblMm = new JLabel("mm");
        lblMm.setBounds(211, 10, 32, 15);
        panel_1.add(lblMm);

        JLabel label_4 = new JLabel("测量深度");
        label_4.setBounds(289, 10, 96, 15);
        panel_1.add(label_4);

        textField_6 = new JTextField();
        textField_6.setEditable(false);
        textField_6.setText("0.0000");
        textField_6.setColumns(10);
        textField_6.setBounds(395, 10, 90, 21);
        textField_6.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                showPopFrame("/Hilfebilder/Taster/twmetifr.jpg");
            }
        });
        panel_1.add(textField_6);

        JLabel label_5 = new JLabel("mm");
        label_5.setBounds(495, 13, 32, 15);
        panel_1.add(label_5);

        JComboBox comboBox = new JComboBox();
        comboBox.setBounds(564, 7, 130, 21);
        panel_1.add(comboBox);

        JLabel label_6 = new JLabel("卡盘长度");
        label_6.setBounds(10, 41, 89, 15);
        panel_1.add(label_6);

        textField_4 = new JTextField();
        textField_4.setEditable(false);
        textField_4.setText("0.0000");
        textField_4.setColumns(10);
        textField_4.setBounds(111, 41, 90, 21);
        textField_4.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                showPopFrame("/Hilfebilder/Spanndl.jpg");
            }
        });
        panel_1.add(textField_4);

        JLabel label_7 = new JLabel("mm");
        label_7.setBounds(211, 41, 32, 15);
        panel_1.add(label_7);

        JLabel label_8 = new JLabel("刀具直径");
        label_8.setBounds(10, 72, 89, 15);
        panel_1.add(label_8);

        textField_7 = new JTextField();
        textField_7.setEditable(false);
        textField_7.setText("0.0000");
        textField_7.setColumns(10);
        textField_7.setBounds(111, 72, 90, 21);
        textField_7.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                showPopFrame("/Hilfebilder/Fraes/zyldur.jpg");
            }
        });
        panel_1.add(textField_7);

        JLabel label_9 = new JLabel("mm");
        label_9.setBounds(211, 72, 32, 15);
        panel_1.add(label_9);

        JLabel label_10 = new JLabel("刀刃数");
        label_10.setBounds(10, 103, 89, 15);
        panel_1.add(label_10);

        textField_8 = new JTextField();
        textField_8.setEditable(false);
        textField_8.setText("0");
        textField_8.setColumns(10);
        textField_8.setBounds(111, 103, 90, 21);
        textField_8.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                showPopFrame("");
            }
        });
        panel_1.add(textField_8);

        JLabel label_11 = new JLabel("旋转角预估");
        label_11.setBounds(10, 131, 89, 15);
        panel_1.add(label_11);

        textField_9 = new JTextField();
        textField_9.setEditable(false);
        textField_9.setText("0.0000");
        textField_9.setColumns(10);
        textField_9.setBounds(111, 131, 90, 21);
        textField_9.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                showPopFrame("/Hilfebilder/Fraes/drallwin.jpg");
            }
        });
        panel_1.add(textField_9);

        JLabel label_12 = new JLabel("°");
        label_12.setBounds(211, 131, 32, 15);
        panel_1.add(label_12);

        JLabel label_13 = new JLabel("测量速度");
        label_13.setBounds(10, 159, 89, 15);
        panel_1.add(label_13);

        textField_10 = new JTextField();
        textField_10.setText("0.0000");
        textField_10.setColumns(10);
        textField_10.setBounds(111, 159, 90, 21);
        textField_10.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                showPopFrame("");
            }
        });
        panel_1.add(textField_10);

        JLabel label_14 = new JLabel("mm");
        label_14.setBounds(211, 159, 32, 15);
        panel_1.add(label_14);

        JLabel lbly = new JLabel("测长探针Y向偏移");
        lbly.setBounds(10, 187, 108, 15);
        panel_1.add(lbly);

        textField_11 = new JTextField();
        textField_11.setText("0.0000");
        textField_11.setColumns(10);
        textField_11.setBounds(111, 184, 90, 21);
        textField_11.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                showPopFrame("/Hilfebilder/Taster/twvsefrz.jpg");
            }
        });
        panel_1.add(textField_11);

        JLabel label_16 = new JLabel("mm");
        label_16.setBounds(211, 187, 32, 15);
        panel_1.add(label_16);

        JLabel lblz = new JLabel("测长探针Z向偏移");
        lblz.setBounds(10, 215, 108, 15);
        panel_1.add(lblz);

        textField_12 = new JTextField();
        textField_12.setText("0.0000");
        textField_12.setColumns(10);
        textField_12.setBounds(111, 212, 90, 21);
        textField_12.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                showPopFrame("/Hilfebilder/Taster/twvsefry.jpg");
            }
        });
        panel_1.add(textField_12);

        JLabel label_17 = new JLabel("mm");
        label_17.setBounds(211, 215, 32, 15);
        panel_1.add(label_17);

        JLabel label_15 = new JLabel("长度探测区间");
        label_15.setBounds(10, 246, 108, 15);
        panel_1.add(label_15);

        textField_13 = new JTextField();
        textField_13.setText("0.0000");
        textField_13.setColumns(10);
        textField_13.setBounds(111, 243, 90, 21);
        textField_13.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                showPopFrame("/Hilfebilder/Taster/Twmesast.jpg");
            }
        });
        panel_1.add(textField_13);

        JLabel label_18 = new JLabel("mm");
        label_18.setBounds(211, 246, 32, 15);
        panel_1.add(label_18);

        JLabel label_19 = new JLabel("长度磨削余量");
        label_19.setBounds(10, 274, 108, 15);
        panel_1.add(label_19);

        textField_14 = new JTextField();
        textField_14.setText("0.0000");
        textField_14.setColumns(10);
        textField_14.setBounds(111, 271, 90, 21);
        textField_14.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                showPopFrame("");
            }
        });
        panel_1.add(textField_14);

        JLabel label_20 = new JLabel("mm");
        label_20.setBounds(211, 274, 32, 15);
        panel_1.add(label_20);

        JLabel label_21 = new JLabel("前刀面磨削量");
        label_21.setBounds(10, 302, 108, 15);
        panel_1.add(label_21);

        textField_15 = new JTextField();
        textField_15.setText("0.0000");
        textField_15.setColumns(10);
        textField_15.setBounds(111, 299, 90, 21);
        textField_15.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                showPopFrame("/Hilfebilder/Fraes/schneire.jpg");
            }
        });
        panel_1.add(textField_15);

        JLabel label_22 = new JLabel("°");
        label_22.setBounds(211, 302, 32, 15);
        panel_1.add(label_22);

        JLabel lbla = new JLabel("测量A轴位置");
        lbla.setBounds(289, 41, 96, 15);
        panel_1.add(lbla);

        textField_16 = new JTextField();
        textField_16.setEditable(false);
        textField_16.setText("0.0000");
        textField_16.setColumns(10);
        textField_16.setBounds(395, 41, 90, 21);
        textField_16.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                showPopFrame("/Hilfebilder/Taster/Wellenschliff_TastenStartpunkt.jpg");
            }
        });

        panel_1.add(textField_16);

        JLabel label_24 = new JLabel("mm");
        label_24.setBounds(495, 44, 32, 15);
        panel_1.add(label_24);

        JLabel label_23 = new JLabel("测量导程距离");
        label_23.setBounds(289, 72, 96, 15);
        panel_1.add(label_23);

        textField_17 = new JTextField();
        textField_17.setEditable(false);
        textField_17.setText("0.0000");
        textField_17.setColumns(10);
        textField_17.setBounds(395, 72, 90, 21);
        textField_17.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                showPopFrame("/Hilfebilder/Fraes/Wellenschliff_LaengeSuchbereich.jpg");
            }
        });

        panel_1.add(textField_17);

        JLabel label_25 = new JLabel("mm");
        label_25.setBounds(495, 75, 32, 15);
        panel_1.add(label_25);

        JLabel label_26 = new JLabel("圆角大小");
        label_26.setBounds(289, 103, 96, 15);
        panel_1.add(label_26);

        textField_18 = new JTextField();
        textField_18.setText("0.0000");
        textField_18.setColumns(10);
        textField_18.setBounds(395, 103, 90, 21);
        textField_18.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                showPopFrame("/Hilfebilder/Fraes/eckra_z.jpg");
            }
        });

        panel_1.add(textField_18);

        JLabel label_27 = new JLabel("mm");
        label_27.setBounds(495, 106, 32, 15);
        panel_1.add(label_27);

        JLabel label_28 = new JLabel("钻尖顶角");
        label_28.setBounds(289, 131, 96, 15);
        panel_1.add(label_28);

        textField_19 = new JTextField();
        textField_19.setText("0.0000");
        textField_19.setColumns(10);
        textField_19.setBounds(395, 131, 90, 21);
        textField_19.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                showPopFrame("/Hilfebilder/Bohr/Spitzwin.jpg");
            }
        });

        panel_1.add(textField_19);

        JLabel label_29 = new JLabel("°");
        label_29.setBounds(495, 134, 32, 15);
        panel_1.add(label_29);

        JLabel label_30 = new JLabel("内冷孔孔径");
        label_30.setBounds(289, 159, 96, 15);
        panel_1.add(label_30);

        textField_20 = new JTextField();
        textField_20.setText("0.0000");
        textField_20.setColumns(10);
        textField_20.setBounds(395, 156, 90, 21);
        textField_20.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                showPopFrame("/Hilfebilder/Lochkdrm.jpg");
            }
        });

        panel_1.add(textField_20);

        JLabel lblMm_1 = new JLabel("mm");
        lblMm_1.setBounds(495, 159, 32, 15);
        panel_1.add(lblMm_1);

        JLabel label_32 = new JLabel("内冷孔旋转角度");
        label_32.setBounds(289, 215, 96, 15);
        panel_1.add(label_32);

        textField_21 = new JTextField();
        textField_21.setText("0.0000");
        textField_21.setColumns(10);
        textField_21.setBounds(395, 215, 90, 21);
        textField_21.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                showPopFrame("/Hilfebilder/Kukanwik.jpg");
            }
        });


        panel_1.add(textField_21);

        JLabel label_33 = new JLabel("°");
        label_33.setBounds(495, 218, 32, 15);
        panel_1.add(label_33);

        textField_22 = new JTextField();
        textField_22.setEditable(false);
        textField_22.setText("0.0000");
        textField_22.setColumns(10);
        textField_22.setBounds(395, 240, 90, 21);
        textField_22.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                showPopFrame("");
            }
        });
        panel_1.add(textField_22);

        JLabel label_35 = new JLabel("°");
        label_35.setBounds(495, 243, 32, 15);
        panel_1.add(label_35);

        JLabel label_34 = new JLabel("旋转角误差区间");
        label_34.setBounds(289, 271, 96, 15);
        panel_1.add(label_34);

        textField_23 = new JTextField();
        textField_23.setText("0.5000");
        textField_23.setColumns(10);
        textField_23.setBounds(395, 271, 90, 21);
        textField_23.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                showPopFrame("");
            }
        });
        panel_1.add(textField_23);

        textField_24 = new JTextField();
        textField_24.setEditable(false);
        textField_24.setText("0.0000");
        textField_24.setColumns(10);
        textField_24.setBounds(395, 296, 90, 21);
        textField_24.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                showPopFrame("");
            }
        });
        panel_1.add(textField_24);

        JLabel label_36 = new JLabel("°");
        label_36.setBounds(495, 274, 32, 15);
        panel_1.add(label_36);

        JLabel label_38 = new JLabel("内冷孔全圆直径");
        label_38.setBounds(289, 184, 96, 15);
        panel_1.add(label_38);

        textField_25 = new JTextField();
        textField_25.setText("0.0000");
        textField_25.setColumns(10);
        textField_25.setBounds(395, 181, 90, 21);
        textField_25.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                showPopFrame("/Hilfebilder/Teilkdrm.jpg");
            }
        });

        panel_1.add(textField_25);

        JLabel lblMm_2 = new JLabel("mm");
        lblMm_2.setBounds(495, 184, 32, 15);
        panel_1.add(lblMm_2);

        JCheckBox checkBox = new JCheckBox("测量长度");
        checkBox.setBackground(Color.WHITE);
        checkBox.setBounds(564, 37, 130, 23);
        panel_1.add(checkBox);

        JCheckBox chckbxa = new JCheckBox("测量A轴位置");
        chckbxa.setBackground(Color.WHITE);
        chckbxa.setBounds(564, 70, 130, 23);
        panel_1.add(chckbxa);

        JCheckBox checkBox_2 = new JCheckBox("测量内冷孔");
        checkBox_2.setBackground(Color.WHITE);
        checkBox_2.setBounds(564, 103, 130, 23);
        panel_1.add(checkBox_2);

        JCheckBox checkBox_3 = new JCheckBox("测量螺旋角");
        checkBox_3.setBackground(Color.WHITE);
        checkBox_3.setBounds(564, 131, 130, 23);
        panel_1.add(checkBox_3);

        JCheckBox checkBox_4 = new JCheckBox("测量分度");
        checkBox_4.setBackground(Color.WHITE);
        checkBox_4.setBounds(564, 159, 130, 23);
        panel_1.add(checkBox_4);

        JCheckBox checkBox_5 = new JCheckBox("测量磨削一体");
        checkBox_5.setBackground(Color.WHITE);
        checkBox_5.setSelected(true);
        checkBox_5.setBounds(564, 187, 130, 23);
        panel_1.add(checkBox_5);

        JCheckBox checkBox_6 = new JCheckBox("调用探针值");
        checkBox_6.setBackground(Color.WHITE);
        checkBox_6.setBounds(564, 215, 130, 23);
        panel_1.add(checkBox_6);

        JPanel panel_2 = new JPanel();
        panel_2.setBackground(Color.WHITE);
        tabbedPane.addTab("探针机械坐标", null, panel_2, null);
        panel_2.setLayout(null);

        JLabel lblx = new JLabel("探针X向距离");
        lblx.setBounds(10, 10, 89, 15);
        panel_2.add(lblx);

        tab2_input1 = new JTextField();
        tab2_input1.setText("0.0000");
        tab2_input1.setEditable(false);
        tab2_input1.setColumns(10);
        tab2_input1.setBounds(111, 10, 90, 21);
        panel_2.add(tab2_input1);

        JLabel label_44 = new JLabel("mm");
        label_44.setBounds(211, 10, 32, 15);
        panel_2.add(label_44);

        JLabel lbly_1 = new JLabel("探针Y向距离");
        lbly_1.setBounds(10, 41, 89, 15);
        panel_2.add(lbly_1);

        tab2_input2 = new JTextField();
        tab2_input2.setText("0.0000");
        tab2_input2.setEditable(false);
        tab2_input2.setColumns(10);
        tab2_input2.setBounds(111, 41, 90, 21);
        panel_2.add(tab2_input2);

        JLabel label_45 = new JLabel("mm");
        label_45.setBounds(211, 41, 32, 15);
        panel_2.add(label_45);

        JLabel lblz_1 = new JLabel("探针Z向距离");
        lblz_1.setBounds(10, 72, 89, 15);
        panel_2.add(lblz_1);

        tab2_input3 = new JTextField();
        tab2_input3.setText("0.0000");
        tab2_input3.setEditable(false);
        tab2_input3.setColumns(10);
        tab2_input3.setBounds(111, 72, 90, 21);
        panel_2.add(tab2_input3);

        JLabel label_47 = new JLabel("mm");
        label_47.setBounds(211, 72, 32, 15);
        panel_2.add(label_47);

        JLabel lblx_1 = new JLabel("内冷孔探针X向距离");
        lblx_1.setBounds(363, 10, 125, 15);
        panel_2.add(lblx_1);

        tab2_input4 = new JTextField();
        tab2_input4.setText("0.0000");
        tab2_input4.setEditable(false);
        tab2_input4.setColumns(10);
        tab2_input4.setBounds(498, 10, 90, 21);
        panel_2.add(tab2_input4);

        JLabel label_46 = new JLabel("mm");
        label_46.setBounds(598, 10, 32, 15);
        panel_2.add(label_46);

        JLabel lbly_2 = new JLabel("内冷孔探针Y向距离");
        lbly_2.setBounds(363, 41, 125, 15);
        panel_2.add(lbly_2);

        tab2_input5 = new JTextField();
        tab2_input5.setText("0.0000");
        tab2_input5.setEditable(false);
        tab2_input5.setColumns(10);
        tab2_input5.setBounds(498, 41, 90, 21);
        panel_2.add(tab2_input5);

        JLabel label_49 = new JLabel("mm");
        label_49.setBounds(598, 41, 32, 15);
        panel_2.add(label_49);

        JLabel lblz_2 = new JLabel("内冷孔探针Z向距离");
        lblz_2.setBounds(363, 72, 125, 15);
        panel_2.add(lblz_2);

        tab2_input6 = new JTextField();
        tab2_input6.setText("0.0000");
        tab2_input6.setEditable(false);
        tab2_input6.setColumns(10);
        tab2_input6.setBounds(498, 72, 90, 21);
        panel_2.add(tab2_input6);

        JLabel label_51 = new JLabel("mm");
        label_51.setBounds(598, 72, 32, 15);
        panel_2.add(label_51);

        JLabel label_37 = new JLabel("密码：");
        label_37.setBounds(10, 156, 43, 15);
        panel_2.add(label_37);

        tab2_pass = new JPasswordField();
        tab2_pass.setBounds(63, 153, 111, 21);
        panel_2.add(tab2_pass);

        JButton tab2_button_confirm = new JButton("确定");
        tab2_button_confirm.setBounds(184, 152, 93, 23);
        tab2_button_confirm.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String tab2Pass = String.valueOf(tab2_pass.getPassword());
                String tab2Password = props.getProperty("tab2.password");
                if (!StrUtil.equals(tab2Pass, tab2Password)) {
                    JOptionPane.showMessageDialog(
                            frame,
                            "密码错误",
                            "提示",
                            JOptionPane.INFORMATION_MESSAGE
                    );
                    return;
                }
                tab2_input1.setEditable(true);
                tab2_input2.setEditable(true);
                tab2_input3.setEditable(true);
                tab2_input4.setEditable(true);
                tab2_input5.setEditable(true);
                tab2_input6.setEditable(true);
            }
        });
        panel_2.add(tab2_button_confirm);

        JButton tab2_button_submit = new JButton("保存");
        tab2_button_submit.setBounds(394, 152, 93, 23);
        panel_2.add(tab2_button_submit);

        JPanel panel_3 = new JPanel();
        panel_3.setBackground(Color.WHITE);
        tabbedPane.addTab("测量跳动", null, panel_3, null);
        panel_3.setLayout(null);

        JLabel label_48 = new JLabel("允许最大跳动值");
        label_48.setBounds(42, 10, 151, 15);
        panel_3.add(label_48);

        textField_32 = new JTextField();
        textField_32.setText("0.0000");
        textField_32.setColumns(10);
        textField_32.setBounds(203, 10, 90, 21);
        panel_3.add(textField_32);

        JLabel lblUm = new JLabel("um");
        lblUm.setBounds(303, 10, 32, 15);
        panel_3.add(lblUm);

        JLabel label_52 = new JLabel("测量跳动点距端面长度");
        label_52.setBounds(42, 41, 151, 15);
        panel_3.add(label_52);

        textField_33 = new JTextField();
        textField_33.setText("0.0000");
        textField_33.setColumns(10);
        textField_33.setBounds(203, 41, 90, 21);
        panel_3.add(textField_33);

        JLabel label_53 = new JLabel("mm");
        label_53.setBounds(303, 41, 32, 15);
        panel_3.add(label_53);

        JLabel lbly_3 = new JLabel("测量跳动Y向探测区间");
        lbly_3.setBounds(42, 72, 151, 15);
        panel_3.add(lbly_3);

        textField_34 = new JTextField();
        textField_34.setText("0.0000");
        textField_34.setColumns(10);
        textField_34.setBounds(203, 72, 90, 21);
        panel_3.add(textField_34);

        JLabel label_55 = new JLabel("mm");
        label_55.setBounds(303, 72, 32, 15);
        panel_3.add(label_55);

        JLabel label_56 = new JLabel("测量跳动位置直径");
        label_56.setBounds(42, 103, 151, 15);
        panel_3.add(label_56);

        textField_35 = new JTextField();
        textField_35.setText("0.0000");
        textField_35.setColumns(10);
        textField_35.setBounds(203, 103, 90, 21);
        panel_3.add(textField_35);

        JLabel label_57 = new JLabel("mm");
        label_57.setBounds(303, 103, 32, 15);
        panel_3.add(label_57);

        JLabel label_58 = new JLabel("测量点数");
        label_58.setBounds(42, 134, 151, 15);
        panel_3.add(label_58);

        textField_36 = new JTextField();
        textField_36.setText("3");
        textField_36.setEditable(false);
        textField_36.setColumns(10);
        textField_36.setBounds(203, 134, 90, 21);
        panel_3.add(textField_36);

        JLabel lblz_3 = new JLabel("测量跳动探针Z向偏移");
        lblz_3.setBounds(42, 165, 151, 15);
        panel_3.add(lblz_3);

        textField_37 = new JTextField();
        textField_37.setText("0.0000");
        textField_37.setColumns(10);
        textField_37.setBounds(203, 165, 90, 21);
        panel_3.add(textField_37);

        JLabel label_61 = new JLabel("mm");
        label_61.setBounds(303, 165, 32, 15);
        panel_3.add(label_61);

        JLabel lbly_4 = new JLabel("测量跳动探针Y向安全距离");
        lbly_4.setBounds(42, 190, 151, 15);
        panel_3.add(lbly_4);

        textField_38 = new JTextField();
        textField_38.setText("0.0000");
        textField_38.setColumns(10);
        textField_38.setBounds(203, 190, 90, 21);
        panel_3.add(textField_38);

        JLabel label_63 = new JLabel("mm");
        label_63.setBounds(303, 190, 32, 15);
        panel_3.add(label_63);

        JCheckBox checkBox_7 = new JCheckBox("测量棒料抖动");
        checkBox_7.setBackground(Color.WHITE);
        checkBox_7.setBounds(43, 227, 103, 23);
        panel_3.add(checkBox_7);

        JButton button_4 = new JButton("连接");
        button_4.setBounds(641, 81, 75, 23);
        button_4.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                try {
                    ftp = new Ftp(ftpHost.getText(), 21, ftpUserName.getText(), String.valueOf(ftpPass.getPassword()));
                } catch (Exception e) {
                    e.printStackTrace();
                    // 消息对话框无返回, 仅做通知作用
                    JOptionPane.showMessageDialog(
                            frame,
                            e.getMessage(),
                            "提示",
                            JOptionPane.INFORMATION_MESSAGE
                    );
                    return;
                }
                // 消息对话框无返回, 仅做通知作用
                JOptionPane.showMessageDialog(
                        frame,
                        "连接成功",
                        "提示",
                        JOptionPane.INFORMATION_MESSAGE
                );
            }
        });
        frame.getContentPane().add(button_4);

        ftpPass = new JPasswordField();
        ftpPass.setBounds(488, 86, 124, 21);
        frame.getContentPane().add(ftpPass);
    }

    /**
     * 读取模版文件内容
     *
     * @param file
     */
    private void readTempleFile(File file) {
        FileReader fileReader = new FileReader(file.getAbsolutePath());
        final List<String> lines = fileReader.readLines();
        lines.forEach(content -> {
            String pattern = "^\\[NR_DATA\\(\\d+\\)].*";
            boolean isMatch = ReUtil.isMatch(pattern, content.trim());
            if (isMatch) {
                List<String> split1 = StrSpliter.split(content, '=', 0, true, true);
                final List<String> split2 = StrSpliter.split(split1.get(1), "(", 0, true, true);
                inputReadMap.put(split1.get(0), new BigDecimal(split2.get(0)).setScale(4, RoundingMode.HALF_UP));
            }
        });
        System.out.println(JSONUtil.toJsonStr(inputReadMap));

    }

    private void showPopFrame(String imgPath) {
        if (StrUtil.isEmpty(imgPath)) {
            if (ObjectUtil.isNotNull(popupFrame)) {
                popupFrame.closeWin();
            }
        } else {
            if (ObjectUtil.isNull(popupFrame)) {
                popupFrame = new PopupFrame(imgPath);
                popupFrame.frame.setVisible(true);
            } else {
                popupFrame.changeBgImg(imgPath);
            }
        }

    }
}
